package com.anxin.registerManagement.controller;

import com.anxin.registerManagement.bean.jo.PostBarSearchJo;
import com.anxin.registerManagement.bean.persist.PostBar;
import com.anxin.registerManagement.service.PostBarService;
import com.anxin.registerManagement.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 叶前呈
 * @date 2022/2/20 14:29
 */
@Api(tags = "贴吧接口")
@RestController
@RequestMapping("/postbars")
public class PostBarController {

    @Autowired
    PostBarService postBarService;

    private static Logger logger = LoggerFactory.getLogger(PostBarController.class);


    /**
     * 查询帖子
     */
    @ApiOperation("查询帖子")
    @PostMapping("/search")
    public ResultUtil getPostBarList(@RequestBody PostBarSearchJo postBarSearchJo) {
        logger.info("查询贴吧：{}", postBarSearchJo);
        return ResultUtil.success(postBarService.getPostBarList(postBarSearchJo));
    }

    /**
     * 发帖
     */
    @ApiOperation("发帖")
    @PostMapping("/add")
    public ResultUtil addPostBar(@Valid @RequestBody PostBar postBar) {
        postBarService.addPostBar(postBar);
        return ResultUtil.success();
    }

    /**
     * 查看帖子
     */
    @ApiOperation("查看帖子")
    @GetMapping("/{id}")
    public ResultUtil getPostBarById(@PathVariable("id") Integer id){
        return ResultUtil.success(postBarService.getPostBarById(id));
    }

    /**
     * 删除帖子
     */
    @ApiOperation("删除帖子")
    @PostMapping("/delete")
    public ResultUtil deletePostBar(@RequestParam("id")List<Integer> id){
        postBarService.deletePostBar(id);
        return ResultUtil.success();
    }

    /**
     * 点赞
     */
    @ApiOperation("点赞帖子")
    @GetMapping("/clickLike/{id}")
    public ResultUtil clickLike(@PathVariable("id") Integer id){
        postBarService.clickLike(id);
        return ResultUtil.success();
    }


}
